//
//  ZLExciseResultHeaderView.m
//  ZLExamination
//
//  Created by Lei_Zhong_Xun on 2017/8/23.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLExciseResultHeaderView.h"
#import "ZLExciseModel.h"

@interface ZLExciseResultHeaderView ()

@property (nonatomic, strong) UIImageView *bgImgv; //卡片背景
@property (nonatomic, strong) UILabel *trueLbl; //答对
@property (nonatomic, strong) UILabel *costTimeLbl; //耗时
@property (nonatomic, strong) UILabel *accuracyLbl; //正确率
@property (nonatomic, strong) UILabel *trueNameLbl; //答对文字
@property (nonatomic, strong) UILabel *costTimeNameLbl; //耗时文字
@property (nonatomic, strong) UILabel *accuracyNameLbl; //正确率文字
@property (nonatomic, strong) UILabel *partLbl; //哪部分课程
@property (nonatomic, strong) UILabel *partDetailLbl; //那部分哪节课程

@end
@implementation ZLExciseResultHeaderView

- (void)setModel:(ZLExciseModel *)model {
    _model = model;
    
    _partLbl.text = _model.curriculum_name;
    _partDetailLbl.text = _model.chapter_name;
    _trueLbl.text = [NSString stringWithFormat:@"%@/%ld",_model.correct_num,_model.correct_num.integerValue+_model.error_num.integerValue];
//    _costTimeLbl.text = @"20/分";
    _costTimeLbl.hidden = YES;
    _costTimeNameLbl.hidden = YES;
    _accuracyLbl.text = [NSString stringWithFormat:@"%@%%",_model.correct_rate];

}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.bgImgv];
        [self addSubview:self.trueLbl];
        [self addSubview:self.costTimeLbl];
        [self addSubview:self.accuracyLbl];
        [self addSubview:self.trueNameLbl];
        [self addSubview:self.costTimeNameLbl];
        [self addSubview:self.accuracyNameLbl];
        [self addSubview:self.partLbl];
        [self addSubview:self.partDetailLbl];
    }
    return self;
}

#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    [_bgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(10);
        make.bottom.equalTo(self.mas_bottom).offset(- 10);
        make.width.mas_equalTo(kSCREEN_WIDTH-20);
        make.centerX.equalTo(self);
    }];
    [_trueLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.width.equalTo(@((kSCREEN_WIDTH - 20) / 3));
        make.height.equalTo(@22);
        make.top.equalTo(self.mas_top).offset(23);
    }];
    [_trueNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_trueLbl.mas_centerX);
        make.width.equalTo(@(60));
        make.height.equalTo(@14);
        make.top.equalTo(_trueLbl.mas_bottom).offset(17);
    }];
    [_costTimeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_trueLbl.mas_right).offset(0);
        make.width.equalTo(@((kSCREEN_WIDTH - 20) / 3));
        make.height.equalTo(@22);
        make.top.equalTo(self.mas_top).offset(23);
    }];
    [_costTimeNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_costTimeLbl.mas_centerX);
        make.width.equalTo(@(60));
        make.height.equalTo(@14);
        make.top.equalTo(_costTimeLbl.mas_bottom).offset(17);
    }];
    [_accuracyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-10);
        make.width.equalTo(@((kSCREEN_WIDTH - 20) / 3));
        make.height.equalTo(@22);
        make.top.equalTo(self.mas_top).offset(23);
    }];
    [_accuracyNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_accuracyLbl.mas_centerX);
        make.width.equalTo(@(60));
        make.height.equalTo(@14);
        make.top.equalTo(_accuracyLbl.mas_bottom).offset(17);
    }];
    [_partLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@(200));
        make.height.equalTo(@20);
        make.top.equalTo(_costTimeNameLbl.mas_bottom).offset(38);
    }];
    [_partDetailLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@(200));
        make.height.equalTo(@20);
        make.top.equalTo(_partLbl.mas_bottom).offset(5);
    }];
}


#pragma mark - lazy load
- (UILabel *)trueLbl {
    if (!_trueLbl) {
        _trueLbl = [[UILabel alloc] init];
        _trueLbl.font = kCX_FONT(21);
        _trueLbl.textAlignment = NSTextAlignmentCenter;
        _trueLbl.textColor = [UIColor whiteColor];
    }
    return _trueLbl;
}

- (UILabel *)costTimeLbl {
    if (!_costTimeLbl) {
        _costTimeLbl = [[UILabel alloc] init];
        _costTimeLbl.font = kCX_FONT(21);
        _costTimeLbl.textAlignment = NSTextAlignmentCenter;
        _costTimeLbl.textColor = [UIColor whiteColor];
    }
    return _costTimeLbl;
}

- (UILabel *)accuracyLbl {
    if (!_accuracyLbl) {
        _accuracyLbl = [[UILabel alloc] init];
//        _accuracyLbl.backgroundColor = [UIColor yellowColor];
        _accuracyLbl.font = kMyFont(21);
        _accuracyLbl.textAlignment = NSTextAlignmentCenter;
        _accuracyLbl.textColor = [UIColor whiteColor];
    }
    return _accuracyLbl;
}
- (UILabel *)trueNameLbl {
    if (!_trueNameLbl) {
        _trueNameLbl = [[UILabel alloc] init];
        _trueNameLbl.font = kMyFont(14);
        _trueNameLbl.textColor = [UIColor whiteColor];
        _trueNameLbl.textAlignment = NSTextAlignmentCenter;
        _trueNameLbl.text = @"答对题";
    }
    return _trueNameLbl;
}

- (UILabel *)costTimeNameLbl {
    if (!_costTimeNameLbl) {
        _costTimeNameLbl = [[UILabel alloc] init];
        _costTimeNameLbl.font = kMyFont(14);
        _costTimeNameLbl.textColor = [UIColor whiteColor];
        _costTimeNameLbl.text = @"练习时长";
        _costTimeNameLbl.textAlignment = NSTextAlignmentCenter;
    }
    return _costTimeNameLbl;
}
- (UILabel *)accuracyNameLbl {
    if (!_accuracyNameLbl) {
        _accuracyNameLbl = [[UILabel alloc] init];
        _accuracyNameLbl.font = kMyFont(14);
        _accuracyNameLbl.textColor = [UIColor whiteColor];
        _accuracyNameLbl.text = @"正确率";
        _accuracyNameLbl.textAlignment = NSTextAlignmentCenter;
    }
    return _accuracyNameLbl;
}
- (UILabel *)partLbl {
    if (!_partLbl) {
        _partLbl = [[UILabel alloc] init];
        _partLbl.font = kMyFont(20);
        _partLbl.textColor = [UIColor whiteColor];
        _partLbl.textAlignment = NSTextAlignmentCenter;
    }
    return _partLbl;
}
- (UILabel *)partDetailLbl {
    if (!_partDetailLbl) {
        _partDetailLbl = [[UILabel alloc] init];
        _partDetailLbl.font = kMyFont(20);
        _partDetailLbl.textColor = [UIColor whiteColor];
        _partDetailLbl.textAlignment = NSTextAlignmentCenter;
    }
    return _partDetailLbl;
}

- (UIImageView *)bgImgv {
    if (!_bgImgv) {
        _bgImgv = [[UIImageView alloc] init];
        _bgImgv.image = kIMAGE(@"result_bg");
    }
    return _bgImgv;
}





@end
